package com.fas.system.service.impl;

import com.fas.common.core.redis.RedisCache;
import com.fas.system.domain.FasInspectionGroup;
import com.fas.system.domain.vo.GroupUser;
import com.fas.system.mapper.FasInspectionGroupMapper;
import com.fas.system.service.IFasInspectionGroupService;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.List;

@Service
public class FasInspectionGroupServiceImpl implements IFasInspectionGroupService {

    @Resource
    private FasInspectionGroupMapper fasInspectionGroupMapper;
    @Resource
    private RedisCache redisCache;

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int insertFasInspectionGroup(FasInspectionGroup fasInspectionGroup) {
        return fasInspectionGroupMapper.insertFasInspectionGroup(fasInspectionGroup);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int updateFasInspectionGroup(FasInspectionGroup fasInspectionGroup) {
        return fasInspectionGroupMapper.updateFasInspectionGroup(fasInspectionGroup);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int deleteFasInspectionGroup(Integer[] groupCodes) {
        return fasInspectionGroupMapper.deleteFasInspectionGroup(groupCodes);
    }

    @Override
    public List<FasInspectionGroup> queryAll(FasInspectionGroup fasInspectionGroup) {
        List<FasInspectionGroup> list = fasInspectionGroupMapper.queryAll(fasInspectionGroup);
        list.forEach(ll -> ll.setCompanyName(FasCooperationCompanyServiceImpl.COMPANY_NAMES.get(ll.getCooperationCompanyId())));
        return list;
    }

    @Override
    public FasInspectionGroup findById(Integer groupCode) {
        return fasInspectionGroupMapper.findById(groupCode);
    }

    @Override
    public List<GroupUser> findXCUsersPage(Integer deptId, Integer groupCode,String userName,String phoneNumber,String iName) {
        List<Integer> userList = null;
        if(groupCode != null){ //新增时 groupCode传空
            userList = fasInspectionGroupMapper.findById(groupCode).getUserList();
        }
        return fasInspectionGroupMapper.findXCUsersPage(deptId,userList,userName,phoneNumber,iName);
    }
}
